/*
 * @Author: liuxiao
 * @Date: 2024-02-25 19:32:11
 * @Last Modified by: liuxiao
 * @Last Modified time: 2024-03-03 23:35:06
 * @ 错误基类
 */

import { clearScreenDown } from 'readline'
import { crpytPassword } from './../middleware/AdminMiddleware'

interface HttpException {
  msg: string
  errorCode: number
  statusCode: number
  code: number
  result: any
}

/**
 * @description:  http异常类基类
 * @param {*} msg 错误提示信息
 * @param {*} errorCode 错误码(开发人员内部约定)
 * @param {*} statusCode HTTP状态码
 * @param {*} result 错误结果
 * @param {*} code  错误返回码，默认为1
 * @return {*}
 */
class HttpException extends Error {
  constructor(
    result = '',
    msg = '服务器异常',
    errorCode = 10000,
    statusCode = 400,
    code = 1
  ) {
    super()
    this.code = code
    this.msg = msg
    this.errorCode = errorCode
    this.statusCode = statusCode
    this.result = result
  }
}

/**
 * @description:参数异常类
 */
class ParameterException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '参数错误',
    errorCode: number = 10000
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

/**
 * @description: 用户验证异常类
 */
class UserValidationException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '用户名或者密码不能为空!',
    errorCode: number = 20000,
    statusCode = 400
  ) {
    super()
    this.statusCode = statusCode
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

/**
 * @description: 加密解密类异常类
 */

class crpytException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '无效的十六进制字符串',
    errorCode: number = 20300,
    statusCode = 406
  ) {
    super()
    this.statusCode = statusCode
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

/**
 * @description: 密码类验证异常类
 */
class PasswordValidationException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '密码修改失败!',
    errorCode: number = 20000,
    statusCode = 401
  ) {
    super()
    this.statusCode = statusCode
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

/**
 * @description:token验证异常类
 */
class TokenValidationException extends HttpException {
  constructor(
    result: any = '',
    msg: string = 'token过期!',
    errorCode: number = 20101,
    statusCode = 510
  ) {
    super()
    this.statusCode = statusCode
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//获取用户信息异常
class GetAdminException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取用户信息错误,用户不存在!',
    errorCode: number = 20200
  ) {
    super()
    this.statusCode = 404
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//发送短信错误
class SmssendException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '短信发送错误!',
    errorCode: number = 210000
  ) {
    super()
    this.statusCode = 500
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//视频点播异常类
class VideoUploadAuthException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '视频上传凭证错误!',
    errorCode: number = 30000
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//获取视频点播异常类
class GetVideoPlayerException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取播放凭证或地址错误!',
    errorCode: number = 30001
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//获取图片上传凭证异常
class GetImageUploadAuthException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取图片上传凭证错粗!',
    errorCode: number = 30002
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//获取课程信息异常类
class GetCourseException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取课程信息错误!',
    errorCode: number = 40001
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//保存课程信息异常类
class saveCourseException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '保存课程信息错误!',
    errorCode: number = 40002
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//章节信息异常类
class ChapterException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取章节信息错误!',
    errorCode: number = 50002
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//新增或更新章节信息异常类
class UpdateChapterException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '新增或更新章节信息错误!',
    errorCode: number = 50002
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//新增或更新课时信息异常类
class UpdateLessonException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '新增或更新课时信息错误!',
    errorCode: number = 50002
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//课时异常类
class LessonException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '查询课时信息错误!',
    errorCode: number = 50003
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//新增或更新章节信息异常类
class UploadImgrException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '图片上传错误!',
    errorCode: number = 60000
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//课程分类异常
class CategoryException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取课程分类错误!',
    errorCode: number = 70000
  ) {
    super()
    this.statusCode = 500
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//视频异常类
class vodException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '视频转码错误!',
    errorCode: number = 80000
  ) {
    super()
    this.statusCode = 500
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

//数据库异常类
class GetModelsException extends HttpException {
  constructor(
    result: any = '',
    msg: string = '获取课程信息异常!',
    errorCode: number = 40000
  ) {
    super()
    this.statusCode = 400
    this.msg = msg
    this.errorCode = errorCode
    this.result = result
  }
}

export {
  HttpException,
  ParameterException,
  UserValidationException,
  GetAdminException,
  SmssendException,
  VideoUploadAuthException,
  GetVideoPlayerException,
  GetModelsException,
  GetCourseException,
  ChapterException,
  UpdateChapterException,
  UploadImgrException,
  CategoryException,
  UpdateLessonException,
  GetImageUploadAuthException,
  vodException,
  LessonException,
  TokenValidationException,
  PasswordValidationException,
  crpytException
}
